(function($){
    var client = new com.im.common.ajax();
    var loading = false;

    var methods = {
        init: function(options) {
            var o = $.extend({
                elmIdSel : "constantSel",//需要展示的位置下拉框
                constParamCode : "",//常量编码
                callbackFunc: function(paramValValue,paramValName) {
                }
            }, options || {});

            var self = this;

            onInit(o);

            return this;
        },
        treeOnClickInner : function(self,opt){
            //加载数据
            return o.treeOnClick('1','test');
        }

    };

    function onInit(opt) {
       //加载数据
        var result = client.callAsJson("commonService/queryBusiConstValByCond", {"constParamCode": opt.constParamCode});
        if (result.success) {
            //规划类型列表添加元素
            $("#"+opt.elmIdSel).append('<option value="">全部</option>');
            if(result.result != undefined){
                $.each(result.result, function (i, item) {
                    $("#"+opt.elmIdSel).append('<option value="'+item.paramValValue+'">'+item.paramValName+'</option>');
                });
            }
            $('.select2').select2();
        }else{
            toastr.error('服务器忙，常量查询失败！'+result.resultMsg);
        }

        //初始化事件
        $("#"+opt.elmIdSel).change(function () {
            _returnFunc(opt);
        });

    };

    function _returnFunc(opt){
        var objvalue = $("#"+opt.elmIdSel).val();
        var objname = $("#"+opt.elmIdSel).find("option:selected").text();
        return opt.callbackFunc(objvalue,objname);
    };
    
    $.fn.constantCommpent = function(method) {

        if (methods[method] && method.charAt(0) != '_') {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' +  method + ' does not exist on jQuery.pagination');
        }
    };

})(jQuery);